package com.xm.xmapp;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;

import com.alibaba.fastjson.JSON;
import com.android.volley.VolleyError;
import com.xm.xmapp.app.MyAppcation;
import com.xm.xmapp.base.BaseActivity;
import com.xm.xmapp.myinterface.DisssmissInterFace;
import com.xm.xmapp.myinterface.GetDataInterFace;
import com.xm.xmapp.request.bean.Get_user_information_statusRequest;
import com.xm.xmapp.request.bean.Zhima_AuthorizeRequest;
import com.xm.xmapp.response.bean.ResponseZhimaAuthorize;
import com.xm.xmapp.response.bean.UserInformationStatusBean;

public class AuthorizeCompleteActivity extends BaseActivity implements OnClickListener {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_rzcomplete);
	}

	@Override
	public void initView() {

	}

	@Override
	public void initData() {
		setMyTitle("实名认证");
		get_user_information_statusRequest();
	}

	@Override
	public void initEvent() {

	}

	private void get_user_information_statusRequest() {
		Get_user_information_statusRequest requestBean = new Get_user_information_statusRequest();
		promptDialog.show();
		MyAppcation.getMyAppcation().getPostData(this, requestBean, new GetDataInterFace<String>() {

			@Override
			public void onResponse(String response) {
				promptDialog.dismiss();
				UserInformationStatusBean statusBean = JSON.parseObject(response, UserInformationStatusBean.class);
				if (statusBean.zhima_is_authorize == 1) {
					findViewById(R.id.zhima).setVisibility(View.GONE);
				} else {
					findViewById(R.id.zhima).setVisibility(View.VISIBLE);
					findViewById(R.id.go).setOnClickListener(AuthorizeCompleteActivity.this);
				}
			}
		}, new DisssmissInterFace() {

			@Override
			public void putError(VolleyError error) {
				promptDialog.dismiss();
			}
		});
	}

	@Override
	public void onClick(View arg0) {
		switch (arg0.getId()) {
		case R.id.go:
			promptDialog.show();
			Zhima_AuthorizeRequest requestBean = new Zhima_AuthorizeRequest();
			MyAppcation.getMyAppcation().getPostData(AuthorizeCompleteActivity.this, requestBean,
					new GetDataInterFace<String>() {

						@Override
						public void onResponse(String response) {

							promptDialog.dismiss();
							ResponseZhimaAuthorize bean = JSON.parseObject(response, ResponseZhimaAuthorize.class);
							intent = new Intent(MyAppcation.getMyAppcation(), ShowURLActivity.class);
							intent.putExtra("url", bean.authorize_url);
							intent.putExtra("title", "芝麻信用");
							startActivity(intent);
							finish();
						}
					}, new DisssmissInterFace() {

						@Override
						public void putError(VolleyError error) {
							promptDialog.dismiss();
						}
					});
			break;

		default:
			break;
		}
	}

}
